//
//  RadioCollectionCell.m
//  aMoment
//
//  Created by dllo on 15/10/3.
//  Copyright © 2015年 LuckyHan. All rights reserved.
//

#import "RadioCollectionCell.h"
#import "AllHeaderFiles.h"

@implementation RadioCollectionCell

- (void)dealloc
{
    [_aboveImageView release];
    [_titleBkgdImageView release];
    [_titleLabel release];
    [_usernameLabel release];
    [_radio release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews
{
    _aboveImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_aboveImageView];
    [_aboveImageView release];
    
    _titleBkgdImageView = [[UIImageView alloc] init];
    _titleBkgdImageView.backgroundColor = [UIColor blackColor];
    _titleBkgdImageView.alpha = .5;
    [self.contentView addSubview:_titleBkgdImageView];
    [_titleBkgdImageView release];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel release];
    
    _usernameLabel = [[UILabel alloc] init];
    _usernameLabel.font = [UIFont systemFontOfSize:14];
    [self.contentView addSubview:_usernameLabel];
    [_usernameLabel release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _aboveImageView.frame = CGRectMake(0, 0, 105 * FIT_WIDTH, 105 * FIT_WIDTH);
    _titleBkgdImageView.frame = CGRectMake(_aboveImageView.X, _aboveImageView.Height - 20 * FIT_HEIGHT, _aboveImageView.Width, 20 * FIT_HEIGHT);
    _titleLabel.frame = _titleBkgdImageView.frame;
    _usernameLabel.frame = CGRectMake(_aboveImageView.X, _aboveImageView.Y + _aboveImageView.Height, _aboveImageView.Width, _titleLabel.Height);
}

- (void)setRadio:(Radio *)radio
{
    if (_radio != radio) {
        [_radio release];
        _radio = [radio retain];
    }
    [_aboveImageView setImageWithURL:[NSURL URLWithString:_radio.coverimg] placeholderImage:[UIImage imageNamed:@"placeholder-cd"]];
    _titleLabel.text = _radio.title;
    _usernameLabel.text = [NSString stringWithFormat:@"by: %@", [_radio.userinfo objectForKey:@"uname"]];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
